import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: '/element',
    name: 'element',
    component: () => import('../views/ElementView.vue'),
    meta: {
      title: 'elementUI组件'
    }
  },
  {
    path: '/axiosview',
    name: 'axiosview',
    component: () => import('../views/AxiosView.vue'),
    meta: {
      title: 'axios接口请求'
    }
  },
  {
    path: '/mobileview',
    name: 'mobileview',
    component: () => import('../views/MobileView.vue'),
    children: [
      {
        path: '',
        component: () => import('../views/mobile/MobileHomeView.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: 'home',
        component: () => import('../views/mobile/MobileHomeView.vue'),
        meta: {
          title: '首页'
        }
      },      
      {
        path: 'categorys',
        component: () => import('../views/mobile/CategorysView.vue'),
        meta: {
          title: '商品分类'
        }
      },      
      {
        path: 'shopcar',
        component: () => import('../views/mobile/ShopcarView.vue'),
        meta: {
          title: '购物车'
        }
      },      
      {
        path: 'profile',
        component: () => import('../views/mobile/ProfileView.vue'),
        meta: {
          title: '个人中心'
        }
      },
      {
        path: 'detail',
        component: () => import('../views/detail/DetailView.vue'),
        meta: {
          title: '商品详情'
        }
      },
    ]
  },
]

const router = new VueRouter({
  routes
})

/* 路由守卫，动态修改浏览器标题 */
router.beforeEach((to,from,next) => {
  next()
  document.title = to.meta.title
})

export default router
